/**
 * 
 */
package com.mbengue.corp.apr.ra.core;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author MMB11447
 *
 */
@Entity
@Table
@NamedNativeQueries(value = {
	    @NamedNativeQuery(name = "articlesD1Auteur", query = "select * from article art where art.auteur=?", resultClass = Article.class),
	    @NamedNativeQuery(name = "articlesParDate", query = "select * from article art where art.dateDeCreation=?", resultClass = Article.class),
	    @NamedNativeQuery(name = "pvReunion", query = "select * from article art where art.type='PV Reunion'", resultClass = Article.class)})
public class Article implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(nullable=false, unique=true, length=64)
	private String titre;
	
	@Column(nullable=false, unique=false, columnDefinition="text")
	private String resume;
	
	//@Lob
	@Column(nullable=false, unique=false, columnDefinition="longtext")
	private String contenu;
	
	@JoinColumn(name="membre", referencedColumnName="email", nullable=false)
	private Membre membre;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false, unique=false, length=16)
	private Date dateDeCreation;
	
	@Column(nullable=false, length=11)
	private String type;
	
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
	@PrimaryKeyJoinColumn
	private Set<Image> images;

	/**
	 * @return the titre
	 */
	public String getTitre() {
		return titre;
	}

	/**
	 * @param titre the titre to set
	 */
	public void setTitre(String titre) {
		this.titre = titre;
	}

	/**
	 * @return the resume
	 */
	public String getResume() {
		return resume;
	}

	/**
	 * @param resume the resume to set
	 */
	public void setResume(String resume) {
		this.resume = resume;
	}

	/**
	 * @return the contenu
	 */
	public String getContenu() {
		return contenu;
	}

	/**
	 * @param contenu the contenu to set
	 */
	public void setContenu(String contenu) {
		this.contenu = contenu;
	}

	/**
	 * @return the membre
	 */
	public Membre getAuteur() {
		return membre;
	}

	/**
	 * @param membre the membre to set
	 */
	public void setAuteur(Membre membre) {
		this.membre = membre;
	}

	/**
	 * @return the dateDeCreation
	 */
	public Date getDateDeCreation() {
		return dateDeCreation;
	}

	/**
	 * @param dateDeCreation the dateDeCreation to set
	 */
	public void setDateDeCreation(Date dateDeCreation) {
		this.dateDeCreation = dateDeCreation;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the images
	 */
	public Set<Image> getImages() {
		return images;
	}

	/**
	 * @param images the images to set
	 */
	public void setImages(Set<Image> images) {
		this.images = images;
	}

	public Article(String titre, String resume, String contenu, Membre auteur,
			Date dateDeCreation, String type, Set<Image> images) {
		super();
		this.titre = titre;
		this.resume = resume;
		this.contenu = contenu;
		this.membre = auteur;
		this.dateDeCreation = dateDeCreation;
		this.type = type;
		this.images = images;
	}
	
	public Article() {
	}

}
